/*
 * Write.cpp
 *
 *  Created on: 03/08/2011
 *      Author: jairo
 */

#include "bilbao/protocol/serial/Write.h"

namespace bilbao
{
	namespace protocol
	{
		namespace serial
		{
			Write::Write()
				: _filaRespostas(0), _serialPort(0)
			{
				//
			}

			Write::Write(SincronyzedQueue* filaRespostas, util::SerialPort* serialPort) :
						_filaRespostas(filaRespostas), _serialPort(serialPort)
			{
				// Do nothing
			}

			Write::~Write()
			{
				delete _serialPort;
				_serialPort = 0;

				delete _filaRespostas;
				_filaRespostas = 0;
			}
			void Write::run()
			{
				String str = "";

				while ( true )
				{
					if ( !_filaRespostas -> empty() )
					{
						_filaRespostas -> pop( str );

						while ( !str.empty() )
						{
							_serialPort -> send( str[0] );
							str.erase( 0, 1 );
						}
					}
				}
			}
		} // namespace serial
	} // namespace protocol
} // namespace bilbao
